﻿using MediatR;
using ProductionManagement.Application.Command.PickCommand;
using ProductionManagement.Infrstructre.lnterface;

namespace ProductionManagement.Application.CommandHandler.PickCommandHandlers
{
    public class BatchDelPickCommandHandlers:IRequestHandler<BatchDelPickCommand,int>
    {
        private readonly IPickRepository _pickRepository;

        public BatchDelPickCommandHandlers(IPickRepository pickRepository)
        {
            _pickRepository = pickRepository;
        }

        public async Task<int> Handle(BatchDelPickCommand request, CancellationToken cancellationToken)
        {
            var ids = (await _pickRepository.GetAll()).Where(x => request.ids.Contains(x.PickingId)).ToList();

            foreach (var item in ids)
            {
                item.IsDel = true;
                item.DelTime = DateTime.Now;
                await _pickRepository.UpdAsync(item);
            }

            return 1;
        }
    }
}
